<!-- Evtl raus nehmen
    <table class="status_table">
    <tr><td class="passed">1</td></tr>
    <tr><td class="active">2</td></tr>
    <tr><td>3</td></tr>
    <tr><td>4</td></tr>
</table> -->

<?php $status = array('Schwebend'   => 'blue',
                      'Festgelegt'  => 'cyan',
                      'Geschlossen' => 'black',
                      'Gebucht'     => 'orange',
                      'Storniert'   => 'red',
                      'Fakturiert'  => 'green',
                      'test1'       => 'red',
                      'test2'       => 'orange',
                     );
?>

<table class="table table-condensed labels-centered" style="width:90%;">
    <tr><td>Thema</td><td><?php echo $measure->course()->title; ?></td></tr>
    <tr><td>Kosten</td><td>NIY</td></tr>
    <tr><td>Teilnehmer</td><td><?php echo $amount_participants; ?></td></tr>
    <tr><td>Veranstalltungsort</td>
        <td>
            <?php echo (!empty($measure->place()->street)) ? $measure->place()->street.' '.$measure->place()->streetnr.'<br >' : ''; ?>
            <?php echo $measure->place()->postalcode.' '.$measure->place()->city;?>
        </td>
    </tr>
    <tr><td>Raum</td><td><?php echo $measure->place()->room; ?></td></tr>
    <tr><td>Trainer</td><td><?php echo (isset($measure->contactdata()->id)) ? $measure->contactdata()->surname.','.$measure->contactdata()->forename.'('.$measure->contactdata()->email.')' : '-'; ?></td></tr>    
    <tr>
        <td>Status</td>
        <td><?php if(!$edit): ?>
            <div rel="tooltip" title="<?php echo $measure->trainingstatus()->description;?>" class="<?php echo $status[$measure->trainingstatus()->name]; ?>" style="width:100px; text-align: center; cursor: help; float: left"><?php echo $measure->trainingstatus()->name ;?></div>&nbsp;
            <a rel="tooltip" title="Status ändern" href="?mode=edit"><i style="float:none" class="icon icon-edit action-icon"></i></a>
            <?php else: ?>
                <?php echo form_open('/measure/edit/'.$measure->id); ?>
                <?php echo form_dropdown('status_select', $status_options); ?>
                <?php echo form_submit('change_status','Ändern', 'class="btn btn-success btn-mini" style="margin-bottom:7px;"'); ?>
                <?php echo form_close(); ?>
            <?php endif; ?>
        </td>
    </tr>
</table>
<br style="clear:both">

<!-- Dunno what happens here, probably
     alternating views depending on
     edit permissions being present/not present?
     If it IS NOT present, go further.
-->
<?php if(!$edit): ?>
<fieldset>                                                  <!-- Hier noch das index.php raus machen, keine ahnung warum die htaccess nicht funzt -->
    <legend>Teilnehmer
        <a title="Listenansicht" href="<?php echo base_url('index.php/measure/details/'.$measure->id.'?display=table');?>"><i style="margin-top:8px;" class="icon-list"></i></a>
        <a title="Blockansicht" href="<?php echo base_url('index.php/measure/details/'.$measure->id.'?display=box');?>"><i style="margin-top:8px;" class="icon-th"></i></a>
    </legend>

    <!-- Are there any participants enlisted?
         If so, here we go!
    -->
    
    <?php if(isset($participants)): ?>

        <!-- Check for desired view style.
             If either <<box>> or nothing is selected, continue here.
        -->
        <?php if($display == 'box' OR !$display): ?>

            <!-- Iterate trough participants -->
            <?php foreach($participants as $participant): ?>
            
            <!-- Output participant information -->
            <div class="profilebox <?php echo ($participant->contactdata()->place()->city !== $measure->place()->city) ? ('gradient_warning') : ('tmt_gradient') ?>">
                   <?php echo $participant->contactdata()->forename .','. $participant->contactdata()->surname; ?><br >
                <p><?php echo mailto($participant->contactdata()->email);?></p>
                <p><?php echo ($participant->contactdata()->phone != NULL) ? ('Telefon: '.$participant->contactdata()->phone) : 'Telefon: -';?></p>
                
                <!-- DOOF -->
                <?php foreach ($participant->team() as $team) {
                    echo '<p>Team: '. $team->name . '</p>';
                }
                ?>

                <p>Standort: <?php echo $participant->contactdata()->place()->city ?></p>
            </div>
            <?php endforeach; ?>
        
        <!-- Check for desired view style.
             If <<table>> is selected, continue here.
        -->
        <?php elseif($display == 'table'): ?>            
            <?php $i=1;?>
            <table class="table table-condensed">
                <tr><th>#</th><th>Name</th><th>Vorname</th><th>E-Mail</th><th>Telefon</th><th>Team</th><th>Standort</th></tr>
            
            <!-- Iterate trough participants -->
            <?php foreach($participants as $participant): ?>

                <!-- Output participant information -->
                <tr <?php echo ($participant->contactdata()->place()->city !== $measure->place()->city) ? ('class="color_warning"') : '' ?>>
                    <td><?php echo $i++;?></td>
                    <td><?php echo $participant->contactdata()->forename; ?></td>
                    <td><?php echo $participant->contactdata()->surname; ?></td>
                    <td><?php echo mailto($participant->contactdata()->email); ?></td>
                    <td><?php echo ($participant->contactdata()->phone != NULL) ? ($participant->contactdata()->phone) : '-'; ?></td>
                    <td>
                        <!-- DOOF -->
                        <?php foreach ($participant->team() as $team) {
                        echo $team->name;
                        }
                        ?>
                    </td>
                    <td><?php echo $participant->contactdata()->place()->city; ?></td>
                </tr>
            <?php endforeach; ?>
            </table>

        <!-- End of view style condition -->
        <?php endif; ?>

    <!-- Are there any participants enlisted?
         If not, throw an error!
    -->
    <?php else: ?>
    <div class="alert alert-danger">Achtung es konnten keine Mitarbeiter geladen werden!</div>

    <!-- End of participant condition -->
    <?php endif; ?>

</fieldset>

<!-- Dunno what happens here, probably
     alternating views depending on
     edit permissions being present/not present?
     If it IS present, go further.
-->
<?php else: ?>
        
        <?php echo form_open('/measure/edit_participants/'.$measure->id, 'autocomplete="off"'); ?>

        <script>
        $(function() {
            $('#participant_add').filterByText($('#filter'));
        });
        </script>

        <?php echo form_input('filter', '' , 'id="filter" placeholder="Text eingeben um zu filtern"'); ?>
        <table>
            <tr>
                <td>
                    <?php 
                    // are there any available employees ready for enlisting?
                    // NO
                    if(!isset($employees_unlisted)){
                        // error message entry
                        $employees_unlisted = array(0 => 'Kein Mitarbeiter verfügbar!');
                        $failswitch = TRUE;
                    }
                    echo form_multiselect('participant_add[]', $employees_unlisted, '', 'id="participant_add" size="10" ');
                    ?>
                </td>
                <td>
                    <?php 
                        if(!isset($failswitch)){ 
                            echo form_submit('change_status','Hinzufügen &raquo;', 'class="btn" style="margin-bottom:7px; width:100px"');
                        }
                    ?>
                    <br >
                    <?php 
                        if(count($employees_listed) > 0) 
                            echo form_submit('change_status','&laquo; Entfernen', 'class="btn" style="margin-bottom:7px; width:100px"'); 
                    ?>
                </td>
                <td><?php 
                        // are there any available members ready to get kicked out?
                        // NO
                        if($amount_participants == 0 || !isset($employees_listed)) 
                            // error message entry
                            $employees_listed = array(0 => 'Kein Mitarbeiter eingeschrieben!');
                        // YES
                        echo form_multiselect('participant_del[]', $employees_listed, '', 'size="10" ');
                    ?>
                </td>
            </tr>
        </table>
        <?php echo form_close(); ?>

<!-- End of alternating permission condition stuff and so on... -->
<?php endif; ?>

<fieldset>
    <legend>Termin</legend>
    <?php if($edit): ?>
        <?php $this->datepicker->display(); ?>
    <?php endif; ?>
</fieldset>

<hr >
<b style="color:#666">Funktionen</b>